package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ListView;
import com.github.clans.fab.FloatingActionMenu;
import com.google.gson.Gson;
import com.isunland.managesystem.R;
import com.isunland.managesystem.adapter.UserGuideAdapter;
import com.isunland.managesystem.base.BaseListFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.OTypticalIssue;
import com.isunland.managesystem.entity.OTypticalIssueListOriginal;
import java.util.ArrayList;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/5/11 16:34
 */
public class UserGuideListFragment extends BaseListFragment implements UserGuideAdapter.Callback {
  //private FileListParams mParams;
  private UserGuideAdapter mAdapter;
  private ArrayList<OTypticalIssue> mList;
  //private String mId;
  //private FUtils mFutils;

  @Override public void initData() {
    super.initData();
    //mParams =
    //    mBaseParams instanceof FileListParams ? (FileListParams) mBaseParams : new FileListParams();
    mList = new ArrayList<>();
    mAdapter = new UserGuideAdapter(mActivity, mList, this);
    mAdapter.setIfDismissMore(true);
    mAdapter.setmIconRes(R.drawable.ic_file_blue_128);
    //mFutils = new FUtils();
  }

  @Override public void initView(View view, Bundle savedInstanceState) {
    super.initView(view, savedInstanceState);
    setTitleCustom(R.string.userGuide);
    setListAdapter(mAdapter);
    FloatingActionMenu floatingActionButton = (FloatingActionMenu) view.findViewById(R.id.fam_menu);
    floatingActionButton.setVisibility(View.GONE);
  }

  @Override public String getUrl() {
    return ApiConst.URL_QUERY_LIST_USER_GUIDE;
  }

  //@Override public HashMap<String, String> getparameters() {
  //  ParamsNotEmpty params = new ParamsNotEmpty();
  //  //params.put("mainId", "59d71bd9-699d-49c7-856f-37c261cdc620");
  //  return params.getParams();
  //}

  @Override public void resolveResponse(String json) {
    OTypticalIssueListOriginal original =
        new Gson().fromJson(json, OTypticalIssueListOriginal.class);
    mList.clear();
    mList.addAll(original.getRows());
    mAdapter.notifyDataSetChanged();
  }

  @Override public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    OTypticalIssue item = mAdapter.getItem(position - mListview.getHeaderViewsCount());
    downloadOrCheck(item);
  }

  private void downloadOrCheck(OTypticalIssue item) {
    if (item == null || TextUtils.isEmpty(item.getOtherFile())) return;
    showDialog(ExtraDownLoadDialogFragment.newInstance("", item.getOtherFile()), 0);
  }

  @Override public void delete(OTypticalIssue item) {
    downloadOrCheck(item);
  }

  @Override public void check(OTypticalIssue item) {
    downloadOrCheck(item);
  }

  @Override protected int setCustomLayoutId() {
    return R.layout.fragment_list_file;
  }

  @Override protected int setCustomtListViewId() {
    return R.id.lv_pullToRefresh;
  }
}
